<template>
  <div id="goodsActivitySearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        :rules="rules"
      >
        <el-form-item label="活动名称" prop="name">
          <el-input
            v-model="formInline.name"
            placeholder="请输入关键词"
            clearable
            maxlength="40"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="活动编号" prop="activityNum">
          <el-input
            v-model="formInline.activityNum"
            placeholder="请输入关键词"
            clearable
            maxlength="40"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="活动类型" prop="activityType">
          <el-select
            v-model="formInline.activityType"
            placeholder="请选择活动类型"
            clearable
          >
            <el-option
              v-for="item in typeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动状态" prop="activityStatus">
          <el-select
            v-model="formInline.activityStatus"
            clearable
            placeholder="请选择活动状态"
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'

export default {
  name: 'goodsActivitySearch',
  msg: '商品活动管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          activityNum: '', //活动编号
          activityStatus: '', // 活动状态
          activityType: '', //活动类型
          name: '' //活动名称
        }
      }
    }
  },
  data() {
    return {
      // 校验规则
      rules: {
        name: [],
        activityNum: [],
        activityStatus: [],
        activityType: []
      },
      // // 协议类型
      typeList: [],
      // // 状态
      statusList: []
    }
  },
  async mounted() {
    // 获取字典的活动类型和活动状态
    const [type, status] = await Promise.all([
      sysNormalDisable('activity_course_type', 'activity_course_type'),
      sysNormalDisable('activity_course_status', 'activity_course_status')
    ])
    this.typeList = type
    this.statusList = status
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less">
#goodsActivitySearch {
}
</style>
